<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  OfficialAccountCommon.php 2018-05-25 14:05 likexin
   
*/

namespace common\library\wechat\officialaccount;

use common\library\wechat\WechatApi;
use common\component\wechat\Wechat;

class OfficialAccountCommon extends WechatApi
{

    /**
     * 生成JSSDK配置参数
     * @param array $APIs 所有接口
     * @param bool $debug 调试模式
     * @param bool $beta 测试版
     * @param bool $json JSON返回
     * @param null $url 定义URL
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/basic-services/jssdk
     */
    public static function jsSdk(array $APIs, $debug = false, $beta = false, $json = true, $url = null)
    {
        if($url) {
            self::getInstance()->jssdk->setUrl($url);
        }
        $result = self::getInstance()->jssdk->buildConfig($APIs, $debug, $beta, $json);
        return Wechat::apiError($result);
    }

    /**
     * 短网址
     * @param string $url 长网址
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/basic-services/url
     */
    public static function shortUrl(string $url)
    {
        $result = self::getInstance()->url->shorten($url);
        return Wechat::apiError($result);
    }

    /**
     * 获取当前设置的回复规则
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/reply
     */
    public static function autoReplyRule()
    {
        $result = self::getInstance()->auto_reply->current();
        return Wechat::apiError($result);
    }

    /**
     * 获取微信服务器 IP(或IP段)
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/base
     */
    public static function getValidIps()
    {
        $result = self::getInstance()->base->getValidIps();
        return Wechat::apiError($result);
    }

    /**
     * 清理接口调用次数
     * @return array|bool|void
     * @others 此接口官方有每月调用限制, 不可随意调用
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/base
     */
    public static function clearQuota()
    {
        $result = self::getInstance()->base->clearQuota();
        return Wechat::apiError($result);
    }

}